<template>
	<view>
		<nav-bar :bgColor="['#4A67D6','#4A67D6']" fontColor="#FFFFFF" title="入库"></nav-bar>
		<view v-if="rfType">
			<view class="orderNumber">数量：{{rfidCodes.length}}</view>
			<view @click="gorfidCodes"
				style="width: 60%;height: 400rpx;border: 6rpx solid #000000;margin: 0 auto;margin-top: 300rpx;border-radius: 15rpx;border-color: #555555;">
				<image style="width: 250rpx;height: 250rpx;margin: 0 auto;margin-top: 50rpx;"
					src="../../static/icon/scanning_ico.png"></image>
				<view style="text-align: center;font-size: 30rpx;color: #808080;margin-top: 20rpx;">请扫描射频标签</view>
			</view>
			<view style="width: 100%;margin-top: 100rpx;">
				<button@click="gorfidCodes"
					style="width: 300rpx;margin: 0 auto;background: #4A67D6;font-size: 30rpx;color: #FFFFFF;">
					下一步</button>
			</view>
		</view>
		<view v-if="!rfType">
			<view @click="gostoreLotNo"
				style="width: 60%;height: 400rpx;border: 6rpx solid #000000;margin: 0 auto;margin-top: 300rpx;border-radius: 15rpx;border-color: #555555;">
				<image style="width: 250rpx;height: 250rpx;margin: 0 auto;margin-top: 50rpx;"
					src="../../static/icon/scan.png"></image>
				<view style="text-align: center;font-size: 30rpx;color: #808080;margin-top: 20rpx;">请扫描二维码标签</view>
			</view>
			<view style="width: 100%;margin-top: 100rpx;">
				<button @click="gorfidCodes"
					style="width: 300rpx;margin: 0 auto;background: #4A67D6;font-size: 30rpx;color: #FFFFFF;">
					上一步</button>
			</view>
		</view>
	</view>
</template>

<script>
	var main = null;
	var receiver = null;
	// import htzImageUpload from '@/components/htz-image-upload/htz-image-upload-show.vue'
	export default {
		// components: {
		// 	htzImageUpload,
		// },
		data() {
			return {
				rfType: true,
				rfidCodes: ["E280110C2000758B157D0A8B", "232323"],
				storeLotNo: 'BC010302'
			}
		},
		onLoad() {
			console.log("onLoad");
			this.get_gb();
		},
		onBackPress() {
			if (receiver != null) {
				main.unregisterReceiver(receiver)
			}
		},
		methods: {

			gorfidCodes() {
				this.rfType = !this.rfType
			},
			gostoreLotNo() {
				var that = this;
				let opt = {
					url:'oms/tbRelateItemTakeDetail/inBoundWarehouseFromPda',
					method:'POST'
				};
				let params = {
					rfidCodes: that.rfidCodes,
					storeLotNo: that.storeLotNo
				};
				this.$http.httpTokenRequest(opt,params).then(res => {
					uni.showToast({
						title: res.data.msg,
						position:'center',
						icon:'success'
					});
				})
				// uni.scanCode({
				//     success: function (res) {
				//         console.log('条码类型：' + res.scanType);
				//         console.log('条码内容：' + res.result);
				// 		that.storeLotNo = res.result
				//     }
				// });
				// uni.showToast({
				// 	title:'入库成功',
				// 	position:'center',
				// 	icon:'success'
				// });
				// setTimeout(()=>{
				// 	uni.navigateBack({
				// 		delta: 1
				// 	});
				// },1500)
			},
			get_gb() {
				var that = this;
				main = plus.android.runtimeMainActivity();
				receiver = plus.android.implements('io.dcloud.android.content.BroadcastReceiver', {
					onReceive: function(context, intent) {
						plus.android.importClass(intent);
						var data = intent.getExtra("data");
						if (data) {
							// that.rfId = data
							that.rfidCodes.push(data)
							console.log(that.rfidCodes)
						}
					}
				});
				var IntentFilter = plus.android.importClass('android.content.IntentFilter');
				let filter = new IntentFilter();
				filter.addAction('android.rfid.epccode');
				var info = main.registerReceiver(receiver, filter)
				// main.unregisterReceiver(receiver)
			},
			deleteImg(e) {
				console.log(e)
			},
			ceshiChooseSuccess(tempFilePaths, e) { //选择图片返回
				console.log('ceshiChooseSuccess', tempFilePaths, e);
				// this.imageData=this.imageData.concat(tempFilePaths)

				//this.imageData.push(...tempFilePaths)
				/****************
				以下代码是自定义上传逻辑，仅供参考
				***************/
				this.tempFilePaths = tempFilePaths
				// this.imageData.push(tempFilePaths[0]);
				this.imgUpload(tempFilePaths);
				console.log(tempFilePaths)
				/*******************************/
			},
			imgUpload(tempFilePaths) {
				if (!tempFilePaths) {
					uni.showToast({
						title: '请上传视频或者照片！',
						position: 'center',
						icon: 'error'
					});
					return
				}
				uni.showLoading({
					title: '上传中'
				});
				console.log('imgUpload', tempFilePaths)
				let uploadImgs = [];
				tempFilePaths.forEach((item, index) => {
					uploadImgs.push(new Promise((resolve, reject) => {
						console.log(index, item)
						uni.uploadFile({
							url: "http://183.246.198.66:29527/sys/file/upload", //仅为示例，非真实的接口地址
							filePath: item,
							// header:{
							// 	'Authorization':'Bearer ' + uni.getStorageSync('token')
							// },
							name: 'file',
							// formData: {
							// 	eventType: this.infoList.eventType, //事件类型
							// 	fireDegree: this.infoList.fireDegree, //火情等级
							// 	wormType: this.infoList.wormType, //病虫害类型
							// 	wormDegree: this.infoList.wormDegree, //病虫害等级
							// 	locationDesc: this.infoList.locationDesc + this.addressName, //地址
							// 	latitude: this.infoList.latitude, //经度
							// 	altitude: this.infoList.altitude //维度
							// },
							success: (uploadFileRes) => {
								console.log('uploadFileRes', uploadFileRes)
								resolve(uploadFileRes);
								var _res = JSON.parse(uploadFileRes.data);
								if (_res.code == 200) {
									console.log(_res.data)
									let str = _res.data
									let fileType = str.lastIndexOf(".")
									str = str.substring(fileType + 1, str.length);
									console.log(str)
									if (str == 'jpeg' || str == 'jpg' || str == 'png') {
										this.imageData.push(
											'http://183.246.198.66:29528/' + _res.data);
										this.fileStatus = true
										console.log('推送jpeg进数组')
									} else if (str == 'mp4') {
										// this.videoPath = 'http://115.29.199.1:81/' + _res.data
										this.imageData.push(
											'http://183.246.198.66:29528/' + _res.data);
										this.fileStatus = true
										console.log('推送mp4进数组')
										console.log(this.infoList.picCt)
									}
								}
							},
							fail: (err) => {
								console.log(err);
								reject(err);
							},
							complete: () => {
								//uni.hideLoading();
							}
						});
					}))
				})
				Promise.all(uploadImgs) //执行所有需请求的接口
					.then((results) => {
						uni.hideLoading();
					})
					.catch((res, object) => {
						uni.hideLoading();
					});
			}
		}
	}
</script>

<style>
	page {
		background: #f8f8f8;
	}

	.content {
		padding: 20rpx;
		letter-spacing: 2rpx;
		font-size: 35rpx;
		color: #646464;
		border-bottom: 1px solid #e2e2e2;
	}

	.contentFont {
		padding: 5rpx;
	}

	.orderNumber {
		margin: 30rpx 30rpx;
		font-size: 35rpx;
		font-weight: bold;
	}
</style>
